package indi.kider.server.applet.api;

import indi.kider.common.model.apabus.Bus;
import indi.kider.common.model.apabus.ServiceDelivery;
import indi.kider.server.applet.model.User;
import indi.kider.server.applet.service.BusService;
import indi.kider.server.applet.service.CommService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.vankid.common.model.base.CommonResponse;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping(value = "bus")
public class BusController {

    @Autowired
    private BusService  busService;
    @Autowired
    private CommService commService;

    @PostMapping("applet/getBus")
    public CommonResponse<List<Bus>> getBusInfo(@RequestBody Bus bus, HttpServletRequest request) {
        User user = commService.getCurrentUser(request, new User());
        return busService.getBusInfo(bus, user);
    }

    @PostMapping("applet/updateBus")
    public CommonResponse<String> updateBusInfo(@RequestBody Bus bus) {
        return busService.updateBusInfo(bus);
    }

    @PostMapping("applet/serviceDelivery")
    public CommonResponse<String> serviceDelivery(@RequestBody Bus bus, HttpServletRequest request) {
        User user = commService.getCurrentUser(request, new User());
        busService.rentBusSubmit(bus, user);
        return CommonResponse.buildAddSuccessResponse("");
    }
}

